[Android] Fixed Material controls themeing issue#30415
Merged
PureWeen merged 6 commits intodotnet:inflight/currentfrom Oct 31, 2025
Merged
[Android] Fixed Material controls themeing issue#30415PureWeen merged 6 commits intodotnet:inflight/currentfrom
PureWeen merged 6 commits intodotnet:inflight/currentfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that Android Material controls are themed correctly by introducing a context wrapper, updating handlers to use it, and adding repro tests.
- Added a
MauiMaterialContextThemeWrapperto wrap Android contexts with the Material theme. - Updated
MauiMaterialButtonandCheckBoxHandler.Androidto use the new theme wrapper. - Added a HostApp sample page and corresponding UI tests to validate the fix for Issue #13356.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs | New wrapper class to apply the correct Material theme to Android views. |
| src/Core/src/Platform/Android/MauiMaterialButton.cs | Updated button constructors to use MauiMaterialContextThemeWrapper. |
| src/Core/src/Handlers/CheckBox/CheckBoxHandler.Android.cs | Updated MaterialCheckBox instantiation to use the theme wrapper. |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue13356.cs | Added UITests for Material button and checkbox dialogs on Android. |
| src/Controls/tests/TestCases.HostApp/Issues/Issue13356.cs | Added HostApp sample page and dialog implementation for Issue #13356. |
Comments suppressed due to low confidence (1)
src/Controls/tests/TestCases.HostApp/Issues/Issue13356.cs:45
- The dialog's Button is missing an AutomationId, so the test
WaitForElement("Dialog Button")may not locate it. Consider setting anAutomationIdon this Button (e.g.,AutomationId = "DialogButton") to match the test or update the test to query by text explicitly.
Content = new Button { Text = "Dialog Button", Padding = new Thickness(30) }
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue13356.cs
Outdated
Show resolved
Hide resolved
jsuarezruiz
approved these changes
Oct 27, 2025
|
|
||
| namespace Microsoft.Maui.Platform; | ||
|
|
||
| internal class MauiMaterialContextThemeWrapper : ContextThemeWrapper |
Contributor
There was a problem hiding this comment.
Each call wraps the context in a new ContextThemeWrapper. This is lightweight but worth monitoring if frequently recreated during inflation.
PureWeen
pushed a commit
that referenced
this pull request
Nov 11, 2025
* Fixed Exception * Optimized code * Updated fix * fixed checkbox * enabled android test * Fixed typo
github-actions bot
pushed a commit
that referenced
this pull request
Nov 11, 2025
* Fixed Exception * Optimized code * Updated fix * fixed checkbox * enabled android test * Fixed typo
github-actions bot
pushed a commit
that referenced
this pull request
Nov 14, 2025
* Fixed Exception * Optimized code * Updated fix * fixed checkbox * enabled android test * Fixed typo
github-actions bot
pushed a commit
that referenced
this pull request
Nov 15, 2025
* Fixed Exception * Optimized code * Updated fix * fixed checkbox * enabled android test * Fixed typo
github-actions bot
pushed a commit
that referenced
this pull request
Nov 15, 2025
* Fixed Exception * Optimized code * Updated fix * fixed checkbox * enabled android test * Fixed typo
github-actions bot
pushed a commit
that referenced
this pull request
Nov 18, 2025
* Fixed Exception * Optimized code * Updated fix * fixed checkbox * enabled android test * Fixed typo
github-actions bot
pushed a commit
that referenced
this pull request
Nov 18, 2025
* Fixed Exception * Optimized code * Updated fix * fixed checkbox * enabled android test * Fixed typo
github-actions bot
pushed a commit
that referenced
this pull request
Nov 18, 2025
* Fixed Exception * Optimized code * Updated fix * fixed checkbox * enabled android test * Fixed typo
github-actions bot
pushed a commit
that referenced
this pull request
Nov 20, 2025
* Fixed Exception * Optimized code * Updated fix * fixed checkbox * enabled android test * Fixed typo
github-actions bot
pushed a commit
that referenced
this pull request
Nov 20, 2025
* Fixed Exception * Optimized code * Updated fix * fixed checkbox * enabled android test * Fixed typo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Root cause
The problem is that the
MauiMaterialButtonstyle has a parent ofWidget.MaterialComponents.Button.UnelevatedButton, which requires the application theme to be based on Theme.MaterialComponents. However, theMauiMaterialButtonconstructor is wrapping the context with just the button style, not ensuring the proper theme hierarchy.Description of change
Theme.MaterialComponent) to avoid runtime exceptions. It introduces a newMauiMaterialContextThemeWrapperto ensure the correct theme is applied to Material components and adds test cases to validate the changes.Fix for Material Component Theme Issue:
src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs: AddedMauiMaterialContextThemeWrapperclass to wrap the Android context with the appropriate Material theme (Resource.Style.Maui_MainTheme_Base). This ensures Material components use the correct theme.src/Core/src/Handlers/CheckBox/CheckBoxHandler.Android.cs: UpdatedCheckBoxHandlerto useMauiMaterialContextThemeWrapper.Create(Context)when creatingMaterialCheckBox, ensuring the correct theme is applied.src/Core/src/Platform/Android/MauiMaterialButton.cs: ModifiedMauiMaterialButtonto useMauiMaterialContextThemeWrapper.Create(context)for all constructors, ensuring consistent theme application for Material buttons.Reference
maui/src/Compatibility/Material/src/Android/MaterialButtonRenderer.cs
Lines 42 to 43 in aac6557
https://github.com/dotnet/maui/blob/main/src/Compatibility/Material/src/Android/MaterialContextThemeWrapper.cs
Validated the behaviour in the following platforms
Issues Fixed
Fixes #13356
Output
After.mov